package br.com.redefranciscanas.wiki.util;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

import org.apache.log4j.Logger;

public class PersistenceUtil { 
	private static final EntityManagerFactory factory;
	private static Logger logger = Logger.getLogger(PersistenceUtil.class);

	static {
		try {
			factory = Persistence.createEntityManagerFactory("wiki");
		} catch (Throwable ex) {
			logger.info("EntityManagerFactory falhou! ", ex);
			throw new RuntimeException(ex);
		}
	}

	public static EntityManager getEntityManager() {
		return factory.createEntityManager();
	}
	
	public static EntityManagerFactory getFactory(){
		return factory;
	}

	public static void closeSession(EntityManager em) {
		em.close();
	}

	public static void closeFactory() {
		factory.close();
	} 
}
